<?php
class EmailAction extends CommonAction {
	private $emailKey = 'sfw3odmn109sqppq';
	public function index()
	{
		$User = M('User');
		$userList = $User->where('user_email_verify = 0')->select();
		$this->assign('userList',$userList);
		$this->display();
	}

	function reSend()
	{
		$user_id = $_POST['user_id'];
		$email		=$_POST['user_email'];
		vendor ( 'PHPMailer.phpmailer' );
		$mail = new PHPMailer ();
		$mail->IsSMTP ();
		//$mail->Host = 'smtp.ym.163.com';
		$mail->Host = 'mail6.myhostadmin.net';
		//$mail->Host = 'smtp.exmail.qq.com';
		//$mail->Host = 'smtp.exmail.sina.com';
		$mail->SMTPAuth = true;
		$mail->Username = 'service@addindex.com';
		$mail->Password = 'wodeyuan1989';
		$mail->From = 'service@addindex.com';
		$mail->FromName = 'Addindex';
		$mail->AddAddress ( $email );
		$mail->IsHTML ( true );
		$mail->CharSet = "utf-8";
		$mail->Subject = "来自百度指数公开版的邮箱验证";
		$url = 'http://www.addindex.com/Register/verifyEmail/?key=' . base64_encode ( $user_id . '+' . md5 ( $user_id . $email . $this->emailKey ) );
		$html = '<html><head><meta http-equiv="Content-Language" content="zh-cn"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>';
		$html .= '<p>请 <a href="' . $url . '" target="_blank" style="color:red">点击这里</a> 完成邮箱验证</p>';
		$html .= '<p>或者直接复制 ' . $url . ' 到浏览器窗口完成邮箱验证</p>';
		$html .= '</body></html> ';
		$mail->Body = $html;
		if (! $mail->Send ()) {
			echo "Message could not be sent. <p>";
			echo "Mailer Error: " . $mail->ErrorInfo;
		}else{
			echo 1;
		}
		exit ();
	}

	function test()
	{
		
		$user_id	= '1';
		$email		= '16989222@qq.com';
		vendor ( 'PHPMailer.phpmailer' );
		$mail = new PHPMailer ();
		$mail->IsSMTP ();
		$mail->Host = M('Config')->getFieldByConfigName('emailSmtp','config_value');
		$mail->Username = 'service@addindex.com';
		$mail->Password = 'wodeyuan1989';
		$mail->SMTPAuth = true;
		$mail->From = 'service@addindex.com';
		$mail->FromName = 'Addindex';
		$mail->AddAddress ( $email );
		$mail->IsHTML ( true );
		$mail->CharSet = "utf-8";
		$mail->Subject = "来自百度指数公开版的邮箱验证";
		$url = 'http://www.addindex.com/Register/verifyEmail/?key=' . base64_encode ( $user_id . '+' . md5 ( $user_id . $email . $this->emailKey ) );
		$html = '<html><head><meta http-equiv="Content-Language" content="zh-cn"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>';
		$html .= '<p>请 <a href="' . $url . '" target="_blank" style="color:red">点击这里</a> 完成邮箱验证</p>';
		$html .= '<p>或者直接复制 ' . $url . ' 到浏览器窗口完成邮箱验证</p>';
		$html .= '</body></html> ';
		$mail->Body = $html;
		if (! $mail->Send ()) {
			echo "Message could not be sent. <p>";
			echo "Mailer Error: " . $mail->ErrorInfo;
		}else{
			echo 1;
		}
		exit ();
	}


	function tixing()
	{
		set_time_limit(0);
		$User = M('User');
		$userList = $User->where('user_email_verify = 0')->order('user_register_time desc')->limit(10)->select();
		foreach($userList as $value)
		{
			vendor ( 'PHPMailer.phpmailer' );
			$mail = new PHPMailer ();
			$mail->IsSMTP ();
			$mail->Host = 'smtp.qq.com';
			$mail->SMTPAuth = true;
			$mail->Username = '536252530@qq.com';
			$mail->Password = 'wodeyuan1989';
			$mail->From = 'addindex@qq.com';
			$mail->FromName = '百度指数公开版';
			$mail->AddAddress ( $value['user_email']);
			$mail->IsHTML ( true );
			$mail->CharSet = "utf-8";
			$mail->Subject = "您好，如果您注册的addindex.com的激活邮件没有收到，请到垃圾箱中查看";
			$html = '您好，如果您注册的addindex.com的激活邮件没有收到，请到垃圾箱中查看。点击并激活。谢谢。';
			$mail->Body = $html;
			$mail->Send ();
			sleep(3);
		}
	}

}